const axios = require('axios')
const sign = require('./sign/xhs/index');


var args = process.argv.slice(2);
console.log("脚本参数：" + args)


function getNoteGet(api) {
    console.log("请求api" + api)
    const baseUrl = "https://edith.xiaohongshu.com"
    const {traceId, xs, xsCommon, xt, cookie} = sign(api)

    return axios({
        url: baseUrl + api,
        method: 'get',
        headers: {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
            'X-B3-Traceid': traceId,
            'X-S': xs,
            'X-S-Common': xsCommon,
            'X-T': xt,
            'Cookie': cookie
        }
    });
}

function isString(obj) { //判断对象是否是字符串
    return Object.prototype.toString.call(obj) === "[object String]";
}

const run = async (api) => {
    const {status, data} = await getNoteGet(api)
    if (status === 200) {
        if (isString(data)) {
            console.log("xhs=" + data)
        } else {
            console.log("xhs=" + JSON.stringify(data))
        }

    } else {
        throw new Error('获取失败')
    }
}
run(args[0])